/**
 * Created by Freeman on 2016/8/8.
 */
import React,{PropTypes} from 'react'
import {getCookie} from '../../utils/authService'
import {API_ROOT} from '../../config'
const SNSLogin = ({logins}) =>{

    let handleSnsLogin = (e,provider) =>{
        e.preventDefault()
        let search = API_ROOT + 'auth/' + provider + '?redirectUrl=' + window.location.origin
        const token = getCookie('token')
        if (token) {
            search += '&access_token=' + token.replace(/(^\")|(\"$)/g, '')
        }
        window.location.href = search
    };
    SNSLogin.propTypes = {
        logins: PropTypes.array.isRequired
    };

    return (
        <div className="login-sns">
            <ul>
                {logins.map((item,i)=>
                    <li key={i} onClick={e=>handleSnsLogin(e,item)}>
                        <a className={item} href="javascript:;"><i className={'fa fa-' + item}></i></a>
                    </li>
                )}
            </ul>
        </div>
    )
};

export default SNSLogin;